<template>
  <div class="page-container">
    <!--面包屑导航-->
    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>营销中心</el-breadcrumb-item>
        <el-breadcrumb-item>基础信息管理</el-breadcrumb-item>
        <el-breadcrumb-item>结算优先级设置</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!--页面标题-->
    <p class="font22 mb30">结算优先级设置</p>
    <!--工具栏-->
    <div class="toolbar" >
      
      <el-row>
        <!--表格内容栏-->
        <el-table
          :data="pageResult"
          :max-height="countHeight(maxHeight)"
          :size="size"
           align="left"
          :header-cell-style="{ 'color': '#FFF','background-color': '#2F4554'}"
           border
           >
          <el-table-column
            label="结算优先级类型"
            align="center"
            prop="typeDesc"
            >
          </el-table-column>
          
          <el-table-column
            label="显示顺序"
            align="center"
            prop="sort">
            <template slot-scope="scope">
              <el-button  type="text" class="btnText" @click="handleUpdateSort(1,scope.row,scope.$index)" :disabled="(pageResult && pageResult.length > 0 && pageResult.length ==1) || (scope.$index == 0 && pageRequest.pageNum == 1)">上移</el-button>
              <el-button  type="text" class="btnText" @click="handleUpdateSort(2,scope.row,scope.$index)" :disabled="(pageResult && pageResult.length > 0 && pageResult.length ==1) || (scope.$index == pageResult.length -1 && pageRequest.pageNum == customPageNum)">下移</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <!--分页栏-->
      <div class="toolbar t_r" >
        <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          @current-change="refreshPageRequest"
          :current-page="pageRequest.pageNum"
          :page-size="pageRequest.pageSize"
          :total="totalSize"
          :page-sizes="[5,10, 20, 30, 40]"
          @size-change="handleSizeChange"
        ></el-pagination>
    </div>



    </div>
  </div>
</template>

<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import KtButton from "@/views/Core/KtButton";
import ElRow from "element-ui/packages/row/src/row";
export default {
  components: {
    ElRow,
    PopupTreeInput,
    KtButton
  },
  data() {
    return {
      size: "small",
      labelPosition: "left",
      stripe: true,
      maxHeight: 900,
      filters: {
        name: "", //广告名称
        type: "", //素材类型
        startDate: "", //有效期开始时间
        endDate: "", //有效期结束时间
        status: "0"
      },
      columns: [],
      filterColumns: [],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: [],
      totalSize: 0,
      customPageNum:0,
    };
  },
  methods: {
    // 获取分页数据
    findPage: function(filters) {
      var this_ = this;
      if (filters == undefined || filters == null) {
        filters = {};
      }
      if (this_.adId) {
        filters.adCodeId = this_.adId;
      }
      filters.start = this.pageRequest.pageNum;
      filters.limit = this.pageRequest.pageSize;
      this.utils.request.queryActivityPriorityPage(filters, function(res) {
        if (res && res.code == "0000" && res.data.rows) {
          this_.pageResult = res.data.rows;
          this_.totalSize = Number(res.data.total);
          this_.customPageNum = Math.ceil(this_.totalSize/this_.pageRequest.pageSize);
        } else {
          this_.pageResult = [];
          this_.totalSize = 0;
        }
      });
    },
    //切换状态tab 0：生效中 1：待生效 2：已过期
    handleClick(tab) {
      this.filters.status = tab.name;
      this.findPage(this.filters);
    },
    countHeight(height) {
      var winHeight =
        document.body.clientHeight || document.documentElement.clientHeight;
      if (height > winHeight * 0.7) {
        height = winHeight * 0.7;
      }
      return height;
    },
    // 换页刷新
    refreshPageRequest: function(pageNum) {
      this.pageRequest.pageNum = pageNum;
      this.findPage(this.filters);
    },
    // 换页刷新
    handleSizeChange: function(pageSize) {
      this.pageRequest.pageSize = pageSize;
      this.pageRequest.pageNum = 1;
      this.findPage(this.filters);
    },

    //排序,type：1 上移 2 下移
    handleUpdateSort: function(type, row, index) {
      var this_ = this,
        params = {
          id:row.id,
          sort:row.sort,
          sortType:type
        };
      this.utils.request.updateActivityPrioritySort(params, function(res) {
        if (res && res.code == "0000") {
          this_.findPage();
        } else {
          this_.$message.error(res.msg || "更新失败!");
        }
      });
    }
  },

  mounted() {
    this.findPage(this.filters);
  }
};
</script>

<style scoped lang="scss">
  @import '../../../assets/css/public.scss';
</style>
